#!/bin/bash

# Copyright (c) 2022 FuTeng
# FuYao-RepoPackageTest-System is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#          http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.

# #################################################
# @Author    :   futeng
# @Contact   :   lanshaa123@163.com
# @Desc      :   指定源软件包安装测试
# #################################################


# ！！！！！！测试前请先配置软件源！！！！！！
# ！！！！！！测试前请先配置软件源！！！！！！
# ！！！！！！测试前请先配置软件源！！！！！！
# ！！！！！！测试前请先配置软件源！！！！！！

# ！！！！！！本脚本只执行【指定源】软件包的安装测试！！！！！！

cd /repotest
# pwd

# 被测软件源的repo id
testRepoId=REPOIDUNDERTEST

# 被测软件包名称
package=`cat robot-pkg`

# 创建存放安装结果的目录
mkdir /repotest/install_result  >>/dev/null
# 创建存放卸载结果的目录
mkdir /repotest/uninstall_result  >>/dev/null
# 创建存放安装失败的软件包的结果目录
mkdir /repotest/install_error_log  >>/dev/null
# 创建存放卸载失败的软件包的结果目录
mkdir /repotest/uninstall_error_log  >>/dev/null


# 软件包安装测试
# echo -e "\033[44;37m Now check install $package \033[0m"
# $package=`repoquery --disablerepo=* --enablerepo=$testRepoId $package --envr |awk -F ":" '{print $2}'`
# echo $package >> temp.list
echo "软件包 $package 安装测试"
echo $package >> install.list
yum -y install $package --enablerepo=${testRepoId} >> /repotest/install_result/$package 2>&1
if [ $? -ne 0 ]
then
    #echo $package is not found.
    echo "软件包 $package 安装失败"
    echo $package | tee -a total-install_error.list
    cp -vp /repotest/install_result/$package /repotest/install_error_log
else
    echo $package | tee -a total-install_pass.list
    echo "软件包 $package 安装成功"
fi